package com.ricky;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * SpringBoot运行原理分析
 *
 * 注意  此种方式 默认需要内置tomcat或者内置jetty支持
 */
//开启SpringBoot自动注入配置  等价于原来的SpringBootApplication
//@EnableAutoConfiguration
//开启RestController注解  含有ResponseBody 即非页面形式
@RestController
public class SpringBootApplication {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @GetMapping("/")
    public String home(HttpServletRequest request) {
        logger.info("HelloWorld 访问成功");
        return "Hello World!";
    }

    /**
     *   测试自定义加载文件的方式 ricky01  通过启动设置参数
     *  --spring.config.name=ricky01 --spring.profiles.default=bgt01
     * @param args
     */
    public static void main(String[] args) throws InterruptedException {
        // 可以使用此方法修改默认配置文件名称
//        System.setProperty("spring.config.location", "classpath:/ricky.properties,classpath:/");
//        System.setProperty("spring.config.name", "ricky");
//        System.setProperty("spring.profiles.default", "bgt");
//        System.setProperty("spring.config.location", "ricky.properties");
//        application.setAdditionalProfiles("dev");//设置dev环境
        SpringApplication application = new SpringApplication(SpringBootApplication.class);
        application.run(args);
    }
}